package com.gzlz.budejie.activity;

import java.util.ArrayList;

import name.fuhan.shipin.ShiPinView;
import name.fuhan.tupian_fh.MyImageView;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.gzlz.budejie.PingLunActivity;
import com.gzlz.budejie.R;
import com.gzlz.budejie.bean.JGuKeBean;
import com.gzlz.budejie.bean.JGuKeBean.TieZi;
import com.gzlz.budejie.bean.JGuKeBean.TieZi.ZuiRe;
import com.gzlz.budejie.bean.JUserBean;
import com.gzlz.budejie.utils.BMUtils;
import com.gzlz.budejie.utils.LineInfo;
import com.gzlz.budejie.utils.SP;
import com.gzlz.budejie.view.VoiceView;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.bitmap.BitmapDisplayConfig;
import com.lidroid.xutils.bitmap.callback.BitmapLoadFrom;
import com.lidroid.xutils.bitmap.callback.DefaultBitmapLoadCallBack;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;

/*
 * 	个人界面
 * */
public class GukeActivity extends Activity implements OnClickListener {

	private TextView tv_guke_back;// 返回
	private ImageView iv_guke_more;// 帖子筛选
	private LinearLayout ll_guke_zan;
	private ImageView iv_guke_zan_icon;// 赞图标
	private TextView tv_guke_zan_content;// 赞数量
	private Button btn_guke_guanzhu;// 关注按钮
	private LinearLayout ll_guke_guanzhu;// 关注
	private LinearLayout ll_guke_fensi;// 粉丝
	private ImageView iv_guke_head;// 头像
	RelativeLayout guke_beijing;// 修改背景图
	TextView guke_name_tou;// 最上面的名字
	TextView guke_name_e;// 名字
	ImageView guke_sex;// 性别
	TextView guke_jianjie;// 简介
	TextView guke_guanzhu;// 关注数
	TextView guke_fensi;// 粉丝
	TextView guke_jifen;// 积分
	RadioButton guke_rb_tiezi;// 帖子
	RadioButton guke_rb_pinglun;// 评论
	TextView guke_tiezizongshu;// 帖子数
	TextView guke_zhengdaoxu;// 正序逆序
	LinearLayout guke_neirong;// 内容区域

	public String url用户信息 = "http://api.budejie.com/api/api_open.php?c=user&a=profile&userid=";
	// public String url评论列表 =
	// "http://api.budejie.com/api/api_open.php?c=comment&a=dataList&userID=";
	public String url用户帖子 = "http://api.budejie.com/api/api_open.php?c=topic&a=mytopic";
	String url要访问的用户 = "&visit_uid=";// 13415949
	String url当前用户 = "&uid=";
	// 下标0全部,1图片,2段子,3音频,4视频 值(1:所有； 10:图片； 29:段子； 31:音频；61:不知道是啥)
	String[] url帖子类型 = { "&type=1", "&type=10", "&type=29", "&type=31",
			"&type=41" };

	private JUserBean jUserBean;
	private int guanxi;
	public static HttpUtils httpUtils = new HttpUtils();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.guke);
		initView();
		String uid = getIntent().getStringExtra("uid");

		url用户信息 += uid;
		获取基本信息的本地或网络数据(url用户信息);

		url用户帖子 = url用户帖子 + url当前用户 + uid + url要访问的用户 + uid;
		获取帖子信息的本地或网络数据(url用户帖子, url帖子类型[0]);

	}

	private void 获取帖子信息的本地或网络数据(String 帖子url, String 帖子具体类型) {
		final String 完整的url = 帖子url + 帖子具体类型;
		String json = SP.getString(完整的url);
		if (!TextUtils.isEmpty(json)) {
			JGuKeBean guKeBean = new Gson().fromJson(json, JGuKeBean.class);
			根据Bean去为内容区域填充数据(guKeBean);
		}

		httpUtils.send(HttpMethod.GET, 完整的url, new RequestCallBack<String>() {

			@Override
			public void onFailure(HttpException arg0, String arg1) {
				Toast.makeText(GukeActivity.this, "网络不通!", 0).show();
			}

			@Override
			public void onSuccess(ResponseInfo<String> arg0) {
				JGuKeBean guKeBean = new Gson().fromJson(arg0.result,
						JGuKeBean.class);
				SP.putString(完整的url, arg0.result);
				guke_neirong.removeAllViews();
				根据Bean去为内容区域填充数据(guKeBean);
			}
		});
	}

	private void 根据Bean去为内容区域填充数据(JGuKeBean bean) {
		// TODO
		String 全部 = bean.totals.get("1");
		String 图片 = bean.totals.get("10");
		String 段子 = bean.totals.get("29");
		String 视频 = bean.totals.get("41");
		String 音频 = bean.totals.get("31");
		guke_tiezizongshu.setText("共有" + 全部 + "篇帖子.\n图片" + 图片 + "篇,段子" + 段子
				+ "篇,视频" + 视频 + "篇,音频" + 音频 + "篇.");
		BitmapDisplayConfig bigPicDisplayConfig = new BitmapDisplayConfig();
		bigPicDisplayConfig.setBitmapConfig(Bitmap.Config.RGB_565);

		MyImageView lastMyImageView = null;
		for (int i = 0; i < bean.topics.size(); i++) {
			TieZi tieZi = bean.topics.get(i);
			View view = null;
			switch (Integer.parseInt(tieZi.type)) {
			case 10:// 10图片，41视频,29段子,31声音，
				view = View.inflate(this, R.layout.liebiao_item_tupian, null);
				MyImageView myImageView = (MyImageView) view
						.findViewById(R.id.liebiao_item_imageview);
				String is_gif = tieZi.is_gif;
				String address;
				String address2;
				if ("1".equals(is_gif)) {
					address = tieZi.gifFistFrame;
				} else {
					address = tieZi.image0;
				}
				address2 = tieZi.image1;
				myImageView.setAddress(address, address2, "1".equals(is_gif), tieZi.width,
						tieZi.height, lastMyImageView);
				lastMyImageView = myImageView;
				break;
			case 41:
				view = View.inflate(this, R.layout.liebiao_item_shipin, null);
				ShiPinView shiPinView = (ShiPinView) view
						.findViewById(R.id.liebiao_item_shipinview);
				String videoAddress = tieZi.videouri;
				String imgAdress = tieZi.cdn_img;
				int height = Integer.parseInt(tieZi.height);
				int width = Integer.parseInt(tieZi.width);

				shiPinView.setAddress(imgAdress, videoAddress, null, width,
						height,-1);
				break;
			case 29:
				view = View.inflate(this, R.layout.liebiao_item, null);
				break;
			case 31:
				view = View.inflate(this, R.layout.liebiao_item_shengyin, null);
				VoiceView shengyinView = (VoiceView) view
						.findViewById(R.id.liebiao_item_shengyinview);
				shengyinView.setAddress(tieZi.voiceuri, tieZi.image0);
				break;
			default:
				Log.e("TGAGK", LineInfo.getLineInfo() + "一个意外的TYPE:"
						+ tieZi.type);
				break;
			}
			if (view == null)
				continue;

			// 所有类型通用的内容
			ImageView liebiao_item_icon = (ImageView) view
					.findViewById(R.id.liebiao_item_icon);// 头像
			TextView liebiao_item_name = (TextView) view
					.findViewById(R.id.liebiao_item_name);// 名字
			TextView liebiao_item_time = (TextView) view
					.findViewById(R.id.liebiao_item_time);// 时间
			TextView liebiao_item_text = (TextView) view
					.findViewById(R.id.liebiao_item_text);// 文字内容
			// liebiao_item_view = (LinearLayout)
			// view.findViewById(R.id.liebiao_item_view);//多媒体内容
			ImageView liebiao_item_ding_img = (ImageView) view
					.findViewById(R.id.liebiao_item_ding_img);// 点赞
			TextView liebiao_item_ding_tv = (TextView) view
					.findViewById(R.id.liebiao_item_ding_tv);// 点赞数
			ImageView liebiao_item_cai_img = (ImageView) view
					.findViewById(R.id.liebiao_item_cai_img);// 踩
			TextView liebiao_item_cai_tv = (TextView) view
					.findViewById(R.id.liebiao_item_cai_tv);// 踩数
			ImageView liebiao_item_zhuanfa_img = (ImageView) view
					.findViewById(R.id.liebiao_item_zhuanfa_img);// 转发
			TextView liebiao_item_zhuanfa_tv = (TextView) view
					.findViewById(R.id.liebiao_item_zhuanfa_tv);// 转发数
			ImageView liebiao_item_pinglun_img = (ImageView) view
					.findViewById(R.id.liebiao_item_pinglun_img);// 评论
			TextView liebiao_item_pinglun_tv = (TextView) view
					.findViewById(R.id.liebiao_item_pinglun_tv);// 评论数
			LinearLayout liebiao_item_zuire_ll = (LinearLayout) view
					.findViewById(R.id.liebiao_item_zuire_ll);// 最热评论区域
			TextView liebiao_item_zuire_text = (TextView) view
					.findViewById(R.id.liebiao_item_zuire_text);// 最热评论内容

			// 为点赞添加点击事件
			liebiao_item_ding_img.setOnClickListener(on点赞Listener);
			liebiao_item_ding_tv.setOnClickListener(on点赞Listener);

			// 为踩添加点击事件
			liebiao_item_cai_img.setOnClickListener(on踩Listener);
			liebiao_item_cai_tv.setOnClickListener(on踩Listener);

			// 为转发,分享添加单击事件
			liebiao_item_zhuanfa_img.setOnClickListener(on转发Listener);
			liebiao_item_zhuanfa_tv.setOnClickListener(on转发Listener);

			// 为评论添加点击事件
			liebiao_item_pinglun_img.setOnClickListener(on评论Listener);
			liebiao_item_pinglun_tv.setOnClickListener(on评论Listener);

			liebiao_item_ding_tv.setText(tieZi.love);// 顶
			liebiao_item_cai_tv.setText(tieZi.hate);// 踩
			liebiao_item_zhuanfa_tv.setText(tieZi.repost);// 转发
			liebiao_item_pinglun_tv.setText(tieZi.comment);// 评论数
			liebiao_item_name.setText("id:" + tieZi.screen_name);// 名字
			liebiao_item_text.setText(tieZi.text);// 正文内容
			liebiao_item_time.setText(tieZi.created_at);// 发布时间

			String 顶踩帖子 = SP.getString(SP.顶踩帖子 + tieZi.id);
			liebiao_item_ding_img.setSelected(SP.顶.equals(顶踩帖子));
			liebiao_item_cai_img.setSelected(SP.踩.equals(顶踩帖子));

			// 顶
			liebiao_item_ding_img.setTag(tieZi);
			liebiao_item_ding_tv.setTag(tieZi);

			// 踩
			liebiao_item_cai_img.setTag(tieZi);
			liebiao_item_cai_tv.setTag(tieZi);

			// 转发,分享
			liebiao_item_zhuanfa_img.setTag(tieZi);
			liebiao_item_zhuanfa_tv.setTag(tieZi);

			// 评论
			liebiao_item_pinglun_img.setTag(tieZi);
			liebiao_item_pinglun_tv.setTag(tieZi);

			// 读取最热评论
			ArrayList<ZuiRe> top_cmt = tieZi.top_cmt;
			if (top_cmt == null || top_cmt.size() == 0
					|| !(top_cmt.get(0) instanceof ZuiRe)) {// 如果没有最热评论,隐藏
				liebiao_item_zuire_ll.setVisibility(View.GONE);
			} else {
				liebiao_item_zuire_ll.setVisibility(View.VISIBLE);
				ZuiRe zuiRe = top_cmt.get(0);
				liebiao_item_zuire_text.setText(zuiRe.user.username + "："
						+ zuiRe.content);
			}

			// holder.liebiao_view.setImageBitmap(让精彩填满生活);
			if (!TextUtils.isEmpty(tieZi.profile_image)) {// 设置头像
				BMUtils.display(liebiao_item_icon, tieZi.profile_image,
						bigPicDisplayConfig);
			}

			guke_neirong.addView(view);
		}
		if(lastMyImageView!=null)
		lastMyImageView.theEnd = true;

	}

	boolean 正在发送中;
	private OnClickListener on点赞Listener = new OnClickListener() {
		@Override
		public void onClick(View v) {
			// TODO 待完成
			final TieZi tiezi = (TieZi) v.getTag();
			final LinearLayout dingParent = (LinearLayout) v.getParent();
			final ImageView dingIV = (ImageView) dingParent.getChildAt(0);
			final TextView dingTV = (TextView) dingParent.getChildAt(1);
			LinearLayout parent = (LinearLayout) dingParent.getParent();
			LinearLayout caiParent = (LinearLayout) parent.getChildAt(2);
			ImageView caiIV = (ImageView) caiParent.getChildAt(0);

			if (!正在发送中 && !dingIV.isSelected() && !caiIV.isSelected()) {// 没点赞,也没踩,
				正在发送中 = true;
				new HttpUtils().send(HttpMethod.GET,
						"http://api.budejie.com/api/api_open.php?c=post&a=love&id="
								+ tiezi.id, new RequestCallBack<String>() {

							@Override
							public void onFailure(HttpException arg0,
									String arg1) {
								正在发送中 = false;
								Toast.makeText(GukeActivity.this,
										"网络请求失败,无法点赞!", 0).show();
							}

							@Override
							public void onSuccess(
									final ResponseInfo<String> arg0) {
								正在发送中 = false;
								if (arg0.result.equals("0")) {
									Toast.makeText(GukeActivity.this, "请求失败!",
											0).show();
									return;
								}
								SP.putString(SP.顶踩帖子 + tiezi.id, SP.顶);

								dingIV.setSelected(true);
								dingTV.setTextColor(Color.RED);
								dingTV.setText("+1");
								AlphaAnimation animation = new AlphaAnimation(
										0, 1);
								animation.setDuration(200);
								AlphaAnimation animation3 = new AlphaAnimation(
										1, 0);
								animation3.setStartOffset(200);
								animation3.setDuration(300);
								ScaleAnimation animation2 = new ScaleAnimation(
										0.2f, 1, 0.2f, 1);
								animation2.setDuration(400);
								AnimationSet animationSet = new AnimationSet(
										false);
								animationSet.addAnimation(animation);
								animationSet.addAnimation(animation3);
								animationSet.addAnimation(animation2);
								animationSet
										.setAnimationListener(new AnimationListener() {
											@Override
											public void onAnimationStart(
													Animation animation) {
											}

											@Override
											public void onAnimationRepeat(
													Animation animation) {
											}

											@Override
											public void onAnimationEnd(
													Animation animation) {
												dingTV.setText(arg0.result);
											}
										});
								dingTV.startAnimation(animationSet);
							}
						});
			}
		}
	};

	private OnClickListener on踩Listener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			final TieZi tiezi = (TieZi) v.getTag();
			final LinearLayout caiParent = (LinearLayout) v.getParent();
			final ImageView caiIV = (ImageView) caiParent.getChildAt(0);
			final TextView caiTV = (TextView) caiParent.getChildAt(1);
			LinearLayout parent = (LinearLayout) caiParent.getParent();
			LinearLayout dingParent = (LinearLayout) parent.getChildAt(0);
			ImageView dingIV = (ImageView) dingParent.getChildAt(0);

			if (!正在发送中 && !caiIV.isSelected() && !dingIV.isSelected()) {// 没点赞,也没踩,
				正在发送中 = true;
				new HttpUtils().send(HttpMethod.GET,
						"http://api.budejie.com/api/api_open.php?c=post&a=cai&id="
								+ tiezi.id, new RequestCallBack<String>() {

							@Override
							public void onFailure(HttpException arg0,
									String arg1) {
								正在发送中 = false;
								Toast.makeText(GukeActivity.this,
										"网络请求失败,无法点赞!", 0).show();
							}

							@Override
							public void onSuccess(
									final ResponseInfo<String> arg0) {
								正在发送中 = false;
								if (arg0.result.equals("0")) {
									Toast.makeText(GukeActivity.this, "请求失败!",
											0).show();
									return;
								}
								SP.putString(SP.顶踩帖子 + tiezi.id, SP.踩);
								caiIV.setSelected(true);
								caiTV.setTextColor(Color.RED);
								caiTV.setText("+1");
								AlphaAnimation animation = new AlphaAnimation(
										0, 1);
								animation.setDuration(200);
								AlphaAnimation animation3 = new AlphaAnimation(
										1, 0);
								animation3.setStartOffset(200);
								animation3.setDuration(300);
								ScaleAnimation animation2 = new ScaleAnimation(
										0.2f, 1, 0.2f, 1);
								animation2.setDuration(400);
								AnimationSet animationSet = new AnimationSet(
										false);
								animationSet.addAnimation(animation);
								animationSet.addAnimation(animation3);
								animationSet.addAnimation(animation2);
								animationSet
										.setAnimationListener(new AnimationListener() {
											@Override
											public void onAnimationStart(
													Animation animation) {
											}

											@Override
											public void onAnimationRepeat(
													Animation animation) {
											}

											@Override
											public void onAnimationEnd(
													Animation animation) {
												caiTV.setText(arg0.result);
											}
										});
								caiTV.startAnimation(animationSet);
							}
						});
			}
		}
	};

	private OnClickListener on转发Listener = new OnClickListener() {
		@Override
		public void onClick(View v) {
			// TODO 待完成
			TieZi tiezi = (TieZi) v.getTag();

		}
	};

	private OnClickListener on评论Listener = new OnClickListener() {
		@Override
		public void onClick(View v) {
			TieZi tiezi = (TieZi) v.getTag();
			Intent intent = new Intent(GukeActivity.this, PingLunActivity.class);
			intent.putExtra("tiezi", tiezi);
			GukeActivity.this.startActivity(intent);
		}
	};

	private void 获取基本信息的本地或网络数据(final String 信息url) {
		String bendiJson = SP.getString(信息url);
		if (!TextUtils.isEmpty(bendiJson)) {
			jUserBean = new Gson().fromJson(bendiJson, JUserBean.class);
			展示基本信息数据(jUserBean);
		}

		httpUtils.send(HttpMethod.GET, 信息url, new RequestCallBack<String>() {

			@Override
			public void onFailure(HttpException arg0, String arg1) {
				Toast.makeText(GukeActivity.this, "网络异常", 0).show();
			}

			@Override
			public void onSuccess(ResponseInfo<String> arg0) {
				jUserBean = new Gson().fromJson(arg0.result, JUserBean.class);
				SP.putString(信息url, arg0.result);
				展示基本信息数据(jUserBean);
			}
		});
	}

	private void 展示基本信息数据(JUserBean jUser) {

		// 加载头像
		BMUtils.display(iv_guke_head, jUser.data.profile_image,
				new DefaultBitmapLoadCallBack<ImageView>() {
					@Override
					public void onLoadCompleted(ImageView container,
							String uri, Bitmap bitmap,
							BitmapDisplayConfig config, BitmapLoadFrom from) {
						bitmap = getRoundedCornerBitmap(
								bitmap,
								Math.min(bitmap.getWidth(), bitmap.getHeight()) / 2);
						super.onLoadCompleted(container, uri, bitmap, config,
								from);
					}

					@Override
					public void onLoadFailed(ImageView container, String uri,
							Drawable drawable) {
						drawable = GukeActivity.this.getResources()
								.getDrawable(R.drawable.ic_launcher);
						super.onLoadFailed(container, uri, drawable);
					}

				});

		// 加载背景
		BMUtils.display(guke_beijing, jUser.data.background_image);

		// 设置名字
		guke_name_tou.setText(jUser.data.username);
		guke_name_e.setText(jUser.data.username);

		// 设置性别
		guke_sex.setSelected("f".equals(jUser.data.sex));

		// 设置简介
		if (!TextUtils.isEmpty(jUser.data.introduction)) {
			guke_jianjie.setText(jUser.data.introduction);
		}

		// 关注数
		guke_guanzhu.setText(jUser.data.follow_count);

		// 粉丝
		guke_fensi.setText(jUser.data.fans_count);

		// 关注按钮(0:默认无关系；1：自己；2：已关注；3：我的粉丝；4：相互关注)
		guanxi = Integer.parseInt(jUser.data.relationship);
		btn_guke_guanzhu.setSelected(guanxi == 1 || guanxi == 2 || guanxi == 4);
		String guanzhu;
		switch (guanxi) {
		case 0:
			guanzhu = "关注";
			break;
		case 1:
			guanzhu = "自己";
			break;
		case 2:
			guanzhu = "取消关注";
			break;
		case 3:
			guanzhu = "我的粉丝";
			break;
		case 4:
			guanzhu = "互相关注关注";
			break;
		default:
			guanzhu = "未知" + guanxi;
			break;
		}
		btn_guke_guanzhu.setText(guanzhu);

		// 积分
		guke_jifen.setText(jUser.data.credit);

	}

	public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, float roundPx) {
		Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
				bitmap.getHeight(), Config.ARGB_8888);
		Canvas canvas = new Canvas(output);
		final int color = 0xff424242;
		final Paint paint = new Paint();
		final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
		final RectF rectF = new RectF(rect);
		paint.setAntiAlias(true);
		canvas.drawARGB(0, 0, 0, 0);
		paint.setColor(color);
		canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
		paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
		canvas.drawBitmap(bitmap, rect, rect, paint);
		return output;
	}

	private void initView() {
		tv_guke_back = (TextView) findViewById(R.id.tv_guke_back);
		iv_guke_more = (ImageView) findViewById(R.id.iv_guke_more);
		ll_guke_zan = (LinearLayout) findViewById(R.id.ll_guke_zan);
		iv_guke_zan_icon = (ImageView) findViewById(R.id.iv_guke_zan_icon);
		tv_guke_zan_content = (TextView) findViewById(R.id.tv_guke_zan_content);
		btn_guke_guanzhu = (Button) findViewById(R.id.btn_guke_guanzhu);
		ll_guke_guanzhu = (LinearLayout) findViewById(R.id.ll_guke_guanzhu);
		ll_guke_fensi = (LinearLayout) findViewById(R.id.ll_guke_fensi);
		iv_guke_head = (ImageView) findViewById(R.id.iv_guke_head);
		guke_beijing = (RelativeLayout) findViewById(R.id.guke_beijing);
		guke_name_tou = (TextView) findViewById(R.id.guke_name_tou);
		guke_name_e = (TextView) findViewById(R.id.guke_name_e);
		guke_sex = (ImageView) findViewById(R.id.guke_sex);
		guke_jianjie = (TextView) findViewById(R.id.guke_jianjie);
		guke_guanzhu = (TextView) findViewById(R.id.guke_guanzhu);
		guke_fensi = (TextView) findViewById(R.id.guke_fensi);
		guke_jifen = (TextView) findViewById(R.id.guke_jifen);
		guke_rb_tiezi = (RadioButton) findViewById(R.id.guke_rb_tiezi);
		guke_rb_pinglun = (RadioButton) findViewById(R.id.guke_rb_pinglun);
		guke_tiezizongshu = (TextView) findViewById(R.id.guke_tiezizongshu);
		guke_zhengdaoxu = (TextView) findViewById(R.id.guke_zhengdaoxu);
		guke_neirong = (LinearLayout) findViewById(R.id.guke_neirong);

		// 设置返回点击事件
		tv_guke_back.setOnClickListener(this);
		btn_guke_guanzhu.setOnClickListener(this);

		guke_rb_tiezi.setOnCheckedChangeListener(onCheckedChangeListener);
		guke_rb_pinglun.setOnCheckedChangeListener(onCheckedChangeListener);

		guke_zhengdaoxu.setOnClickListener(this);

	}

	OnCheckedChangeListener onCheckedChangeListener = new OnCheckedChangeListener() {

		@Override
		public void onCheckedChanged(CompoundButton buttonView,
				boolean isChecked) {
			if (isChecked) {
				if (buttonView == guke_rb_tiezi) {
					// TODO 执行加载帖子
				}
				if (buttonView == guke_rb_pinglun) {
					// TODO 加载评论
				}
			}
		}

	};

	// 点击事件
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.tv_guke_back:
			finish();
			break;
		case R.id.iv_guke_more:

			break;
		case R.id.ll_guke_zan:
			if (ll_guke_zan.isSelected()) {
				iv_guke_zan_icon.setSelected(true);
				tv_guke_zan_content.setSelected(true);
			} else {
				iv_guke_zan_icon.setSelected(false);
				tv_guke_zan_content.setSelected(false);

			}
			break;
		case R.id.btn_guke_guanzhu:
			// TODO 待完成
			Toast.makeText(this, "你没登陆", 0).show();

			break;
		case R.id.iv_guke_head:

			break;
		case R.id.ll_guke_guanzhu:

			break;
		case R.id.ll_guke_fensi:

			break;
		case R.id.guke_zhengdaoxu:
			if ("↓正序".equals(guke_zhengdaoxu.getText().toString()))
				guke_zhengdaoxu.setText("↑逆序");
			else
				guke_zhengdaoxu.setText("↓正序");

			int childCount = guke_neirong.getChildCount();
			ArrayList<View> list = new ArrayList<View>(childCount);
			for (int i = 0; i < childCount; i++) {
				list.add(guke_neirong.getChildAt(i));
			}
			guke_neirong.removeAllViews();
			for (int i = list.size() - 1; i >= 0; i--) {
				guke_neirong.addView(list.get(i));
			}

			break;
		default:
			break;
		}
	}
}
